package main.java.indi.zyj.coderecord;

public class MonotoneIncreasingDigits {


    public int monotoneIncreasingDigits(int n) {

        char[] chars = (n + "").toCharArray();
        int start = chars.length;
        for (int i = chars.length - 2; i >= 0; i--) {
            if (chars[i] > chars[i + 1]) {
                chars[i]--;
                start = i + 1;
            }
        }
        for (int i = start; i < chars.length; i++) {
            chars[i] = '9';
        }
        return Integer.parseInt(String.valueOf(chars));

    }


}
